package com.party.course.service.impl;

import java.util.Collections;
import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.party.course.mapper.CoachTimeMapper;
import com.party.course.domain.CoachTime;
import com.party.course.service.ICoachTimeService;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.party.common.utils.SecurityUtils;

/**
 * 教练时间Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@Service
public class CoachTimeServiceImpl extends ServiceImpl<CoachTimeMapper, CoachTime> implements ICoachTimeService {
    @Autowired
    private CoachTimeMapper coachTimeMapper;

    /**
     * 查询教练时间
     *
     * @param id 教练时间主键
     * @return 教练时间
     */
    @Override
    public CoachTime view(String id) {
        return coachTimeMapper.selectCoachTimeById(id);
    }

    /**
     * 查询教练时间列表
     *
     * @param coachTime 教练时间
     * @return 教练时间
     */
    @Override
    public List<CoachTime> findList(CoachTime coachTime) {
        return coachTimeMapper.selectCoachTimeList(coachTime);
    }

    /**
     * 新增教练时间
     *
     * @param coachTime 教练时间
     * @return 结果
     */
    @Override
    public int add(CoachTime coachTime) {
        if (StrUtil.isEmpty(coachTime.getWeek()) || StrUtil.isEmpty(coachTime.getStartTime()) || StrUtil.isEmpty(coachTime.getEndTime())) {
            return 1;
        }
        coachTime.setId(IdUtil.simpleUUID());
        coachTime.setDelFlag("0");
        return coachTimeMapper.insert(coachTime);
    }

    /**
     * 修改教练时间
     *
     * @param coachTime 教练时间
     * @return 结果
     */
    @Override
    public int updateEntity(CoachTime coachTime) {
        coachTime.setUpdateTime(DateUtil.date());
        return coachTimeMapper.updateById(coachTime);
    }

    /**
     * 批量删除教练时间
     *
     * @param ids 需要删除的教练时间主键
     * @return 结果
     */
    @Override
    public int deleteIds(List<String> ids) {
        return coachTimeMapper.deleteCoachTimeByIds(ids);
    }

    /**
     * 删除教练时间信息
     *
     * @param id 教练时间主键
     * @return 结果
     */
    @Override
    public int deleteById(String id) {
        return coachTimeMapper.deleteCoachTimeById(id);
    }

    @Override
    public List<CoachTime> findByCoachId(String id) {
        return coachTimeMapper.findByCoachId(id);
    }

    @Override
    public void deleteByCoachId(String coachId) {
        coachTimeMapper.deleteByCoachId(coachId);
    }
}
